package com.sihan.framework.etm.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.sihan.framework.etm.common.CommonBiz;
import com.sihan.framework.etm.common.RestBiz;
import com.sihan.framework.etm.common.websocket.WebSocketUtil;
import com.sihan.framework.etm.common.util.ISMSTempSendable;
import com.sihan.framework.etm.common.util.SMSConfig;
import com.sihan.framework.etm.dto.TestDTO;
import com.sihan.framework.etm.enums.CacheKeyName;
import com.sihan.framework.etm.mapper.baseData.DeviceMapper;
import com.sihan.framework.etm.mapper.baseData.ToolMapper;
import com.sihan.framework.etm.mapper.business.StationLocationMapper;
import com.sihan.framework.etm.mapper.business.ToolBorrowMapper;
import com.sihan.framework.etm.service.business.ToolPositionService;
import com.sihan.framework.etm.common.AppConfiguration;
import com.sihan.framework.etm.common.CacheOperatorInfo;

import io.swagger.annotations.Api;

@Api(tags = "测试")
@RestController
@RequestMapping("/test")
public class TestController {

	@Autowired
	private CommonBiz commonBiz;
	
	@Autowired
	private WebSocketUtil webSocketUtil;
	
	@Autowired
	private RestTemplate restTemplate;
	
	@Autowired
	private AppConfiguration appConfig;
	
	@Autowired
	private RestBiz restBiz;
	
	@Autowired
	private DeviceMapper deviceMapper;
	
	@Autowired
	private ISMSTempSendable smsSendImpl;
	
	@Autowired
	private SMSConfig sMSConfig;
	
	@Autowired
	private ToolPositionService toolPositionService;
	
	@Autowired
	private StationLocationMapper stationLocationMapper;
	
	@Autowired
	private ToolMapper toolMapper;
	
	@Autowired
	private ToolBorrowMapper toolBorrowMapper;
	
	
	@PostMapping("/test")
	@Async("taskExecutor")
	public @ResponseBody Object test(@RequestBody TestDTO param) {
		commonBiz.setUserOrgIds("f305adc7e1bf11eaac83024277ff3c8a", "604829591829039549");
		System.out.println(CacheOperatorInfo.getMapValue("f305adc7e1bf11eaac83024277ff3c8a", null));
		//commonSendInfo.sendToolBook();
		//设备改为修改时发送
		//人员关系配置改为配置完成发送
		//commonSendInfo.sendDeviceUsersRel(null);
		//commonSendInfo.sendUsers(null);
		//commonSendInfo.getDeviceRunningDataFromFangcang();
		//checkDateSchedule.getDataFromFangcang();
//		if(param.getCode() == 1) {
//			commonSendInfo.getToolBookTest(data1);
//		}else if(param.getCode() == 2) {
//			String data1 = "{ \"successful\": true, \"resultValue\": [ { \"id\": null, \"mechanismId\": \"adea8e50b76911e99595005056835b0c\", \"mechanismName\": \"变电运维室\", \"path\": null, \"backup1\": null, \"backup2\": null }, { \"id\": null, \"mechanismId\": \"d93170a0dac111e98247005056835b0c\", \"mechanismName\": \"海城变电运维三班\", \"path\": null, \"backup1\": null, \"backup2\": null }, { \"id\": null, \"mechanismId\": \"d4dd2e2bdac811e98247005056835b0c\", \"mechanismName\": \"安全监察部_保卫部\", \"path\": null, \"backup1\": null, \"backup2\": null } ], \"resultHint\": \"调用成功\", \"errorPage\": null, \"type\": null }";
//			commonSendInfo.getMechanismTest(data1);
//		}else if(param.getCode() == 3) {
//			String data1 = "{ \"successful\": true, \"resultValue\": [ { \"useOrgid\": \"808081661591be016615ad478c0009gs\", \"useOrg\": \"国网甘肃省电力公司兰州供电公司\", \"useGqid\": \"3a34172f194e44bd947320a1c3b4eegs\", \"userGq\": \"安全监察部（保卫部）\", \"useBzid\": \"3a34172f194e44bd947320a1c3b4eegs\", \"useBzname\": \"安全监察部（保卫部）\", \"useBsid\": null, \"useBsname\": null, \"useBanzid\": \"3a34172f194e44bd947320a1c3b4eegs\", \"useBanzname\": \"安全监察部（保卫部）\", \"blgXgsid\": null, \"blgXgs\": null, \"blgSgsid\": \"808081661591be016615ad478c0009gs\", \"blgSgs\": \"国网甘肃省电力公司兰州供电公司\" } ], \"resultHint\": \"调用成功\", \"errorPage\": null, \"type\": null }";
//			commonSendInfo.getOrgTest(data1);
//		}else if(param.getCode() == 4) {
//			String data1 = "{\"successful\":true,\"resultValue\":[{\"bookid\":\"0037db0bc3894dedbbdb59415d07639f\",\"pkScrapid\":\"06e10700a71e475cb3a4c28a22c92173\",\"scrapNum\":\"1\",\"scrapReason\":\"0\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"绝缘安全工器具\",\"gqjClassify\":\"验电器\",\"gqjStandard\":\"验电器\",\"factoryNum\":\"YDQ000#00000023\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"},{\"bookid\":\"02420d76528045b4a03b9918d33e1e1e\",\"pkScrapid\":\"22602a2a75b2421e9d31120e4206ccb8\",\"scrapNum\":\"1\",\"scrapReason\":\"0\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"绝缘安全工器具\",\"gqjClassify\":\"验电器\",\"gqjStandard\":\"验电器\",\"factoryNum\":\"YDQ000#00000040\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"},{\"bookid\":\"fe2d0a4bf0564b478e02f87f56ff2fa0\",\"pkScrapid\":\"2898d95b5a29429f8f64e4a61fc5c9dd\",\"scrapNum\":\"1\",\"scrapReason\":\"0\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"绝缘安全工器具\",\"gqjClassify\":\"验电器\",\"gqjStandard\":\"验电器\",\"factoryNum\":\"YDQ000#00000088\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"},{\"bookid\":\"0d8cafa6a3ae4ab9bb6e55504acae7a5\",\"pkScrapid\":\"656fe85f22f744deac59826abb75f70b\",\"scrapNum\":\"1\",\"scrapReason\":\"2\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"个体防护装备\",\"gqjClassify\":\"安全帽\",\"gqjStandard\":\"安全帽\",\"factoryNum\":\"AQM000#00000083\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"},{\"bookid\":\"0874f717ab30498aa4edb51c6a53d440\",\"pkScrapid\":\"b8dc0e961edd47ab97a75c22813a961a\",\"scrapNum\":\"1\",\"scrapReason\":\"0\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"绝缘安全工器具\",\"gqjClassify\":\"验电器\",\"gqjStandard\":\"验电器\",\"factoryNum\":\"YDQ000#00000065\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"},{\"bookid\":\"089492664f5b4e9681779d9f09418fd7\",\"pkScrapid\":\"ed4fdc1652ef4cbba538c7cdc3a1c029\",\"scrapNum\":\"1\",\"scrapReason\":\"2\",\"scrapTime\":\"2021-01-06\",\"applyUser\":\"兰州安监\",\"applyTime\":\"2021-01-06\",\"userGq\":\"安全监察部保卫部\",\"useBsname\":\"\",\"useBzname\":\"安全监察部保卫部\",\"useBzid\":\"3a34172f194e44bd947320a1c3b4eegs\",\"gqjClass\":\"个体防护装备\",\"gqjClassify\":\"安全帽\",\"gqjStandard\":\"安全帽\",\"factoryNum\":\"AQM000#00000014\",\"blgXgs\":\"\",\"blgSgs\":\"国网甘肃省电力公司兰州供电公司\",\"isplan\":\"0\",\"path\":null,\"status\":\"0\"}],\"resultHint\":\"调用成功\",\"errorPage\":null,\"type\":null}";
//			commonSendInfo.getScrapTest(data1);
//		}else if(param.getCode() == 5) {
//			String data1 = "{ \"successful\": true, \"resultValue\": [ { \"jobPlanId\": \"1430820d82301a81683df7ca445f2dd4\", \"jobName\": \"计划一\", \"jobContent\": \"111\", \"startTime\": \"2021-01-01\", \"stopTime\": \"2021-01-31\" }, { \"jobPlanId\": \"ab747f920de044b8b0ce39405985ab6e\", \"jobName\": \"计划二\", \"jobContent\": \"222\", \"startTime\": \"2021-01-01\", \"stopTime\": \"2021-01-31\" } ], \"resultHint\": \"调用成功\", \"errorPage\": null, \"type\": null }";
//			commonSendInfo.getTaskTest(data1);
//		}else if(param.getCode() == 6) {
//			String data1 = "{ \"successful\": true, \"resultValue\": [ { \"id\": \"f305adc7e1bf11eaac83024277ff3c8a\", \"baseOrgUnitId\": \"3a34172f194e44bd947320a1c3b4eegs\", \"pwd\": \"\", \"name\": \"gs_lzaj\", \"fullName\": \"兰州安监\", \"status\": 1, \"number\": \"555\", \"phone\": \"\", \"userImage\": null } ], \"resultHint\": \"调用成功\", \"errorPage\": null, \"type\": null }";
//			commonSendInfo.getUserTest(data1);
//		}else if(param.getCode() == 7) {
//			String data1 = "{\"successful\":true,\"resultValue\":[{\"pkGqjcheckId\":\"328dbdeaeeb8a5959aa6e7e12e1be41f\",\"bookId\":\"123b014c92064f5488074c696269ad15\"},{\"pkGqjcheckId\":\"4192edb5b20399437f5d0dc8a4f78a64\",\"bookId\":\"152c02760eae48ab995b4f87244b34a0\"},{\"pkGqjcheckId\":\"a3273257bacfbfc9a046ebc92545ce40\",\"bookId\":\"09e47ac7ed2d48e0b138ff5808282cd9\"},{\"pkGqjcheckId\":\"c99caf9aa3a35fc8c14f66f3eecee40d\",\"bookId\":\"10a83642a9ed4d3392207cfa67e312fd\"}],\"resultHint\":\"调用成功\",\"errorPage\":null,\"type\":null}";
//			commonSendInfo.inspetResultTest(data1);
//		}
		CacheOperatorInfo.setMapValue(CacheKeyName.VALIDATED_USER_ID.getValue(), "f305adc7e1bf11eaac83024277ff3c8a");
		CacheOperatorInfo.setMapValue(CacheKeyName.BUSINESS_MASTER_ID.getValue(), "7dc519d73b5243fab221f3cc5eeb2db8");
		//checkDateSchedule.produceInspect();
		//webSocketUtil.sendMsgForBorrowReturnDetail();
		//CacheOperatorInfo.setMapValue(CacheKeyName.VALIDATED_FACE_IMG.getValue(), null);
		//commonBiz.sendCommandToDevice(code);
		//commonBiz.produceCornerSeri();
		//String zb="104.053172,30.553400";
		//System.out.println(SpaceCoordinatesUtil.changeSpaceCoordinates(zb));
		
//		List<StationLacation> stations = stationLocationMapper.selectList(new Condition<StationLacation>());
//		
//		List<String> coooos = Arrays.asList(stations.get(0).getLocation().split(";"));
//		Collections.reverse(coooos);
//		System.out.println(coooos.toString());
		
//		ToolDTO dto = new ToolDTO();
//		dto.setId(24l);
//		dto.setQueryStartTime("2020-08-28 15:30:04");
//		//dto.setQueryEndTime("2020-08-28 17:33:08");
//		return toolPositionService.lngLatToCoordinateArray(dto);
		//${title}${stationName}工器具库房有${toolNum}个工器具即将过期，请及时安排送检
//		Map<String, Object> paramMap = new HashMap<String, Object>();
//		paramMap.put("stationName", sMSConfig.getStationName());
//		paramMap.put("toolNum", 30);
//		smsSendImpl.sendSmsAsync(appConfig.getInspectRemindPhone(), sMSConfig.getSmsTemp(), paramMap);
		//commonBiz.checkUndoneTask();
		//commonBiz.printCode("q1223");
		//CacheOperatorInfo.setMapValue(
		//		CacheKeyName.BF_TOOL_ID_LIST.getValue(), null);
		//commonBiz.handlerReturnNoDone();
		//checkDateSchedule.execute();
		//commonBiz.sendIvgScanStopCommand();
		//CacheOperatorInfo.flushCashMap();
		//commonBiz.sendIvgScanStartCommand();
		//commonBiz.sendIvgScanStartCommand();
		//checkDateSchedule.execute();
		//CacheOperatorInfo.setMapValue(CacheKeyName.VALIDATED_USER_ID.getValue(), 45l);
		//CacheOperatorInfo.setMapValue(CacheKeyName.BUSINESS_MASTER_ID.getValue(), 0l);
		//ApiResult check = commonBiz.sendCommandToDevice(MqttSendCommandFunc.COMMAND_2060.getValue());
		//CacheOperatorInfo.setMapValue(CacheKeyName.BUSINESS_MASTER_ID.getValue(), 59l);
		//CacheOperatorInfo.setMapValue(CacheKeyName.READER_CODE_LIST.getValue(), 
		//CacheKeyName.READER_CODE_LIST.getValue());
		CacheOperatorInfo.setMapValue(CacheKeyName.BUSINESS_MASTER_ID.getValue(), 144L);
		Integer sendCount = 600;Integer waitDays = 60;
		Integer m = appConfig.getVoltageCount();
		Integer n = appConfig.getVoltageWaitDays();
		BigDecimal a = new BigDecimal(m).divide(new BigDecimal(n),3, RoundingMode.HALF_UP);
		BigDecimal x = new BigDecimal(sendCount).divide(new BigDecimal(4),3, RoundingMode.HALF_UP);
		BigDecimal electricity = (new BigDecimal(m).subtract(x).subtract(
				new BigDecimal(waitDays).multiply(a))).divide(new BigDecimal(m),3, RoundingMode.HALF_UP);
		System.out.println(electricity);
		return electricity;
		//return null;
	}
	public static void main(String[] args) throws IOException {
		Integer a = 1,b=1,c=2;
		System.out.println(a&b&c);
	}
}
